{% extends "base.html" %}

{% block content %}
<div class="page-header">
    <div class="d-flex justify-content-between align-items-center">
        <div>
            <h1 class="page-title">
                <i class="fas fa-code me-2"></i>
                脚本管理
            </h1>
            <p class="page-subtitle">管理和编辑您的Python脚本</p>
        </div>
        <a href="{{ url_for('upload_script') }}" class="btn btn-primary btn-add">
            <i class="fas fa-upload me-2"></i>
            上传脚本
        </a>
    </div>
</div>

{% if scripts %}
<div class="scripts-grid">
    {% for script in scripts %}
    <div class="script-card">
        <div class="script-card-header">
            <div class="script-icon">
                <i class="fab fa-python"></i>
            </div>
            <div class="script-type">
                <span class="badge bg-primary">Python</span>
            </div>
        </div>
        
        <div class="script-card-body">
            <h3 class="script-name">{{ script.name }}</h3>
            
            <div class="script-info">
                <div class="info-item">
                    <i class="fas fa-calendar me-2"></i>
                    <span class="info-label">上传时间:</span>
                    <span class="info-value">{{ script.upload_time.strftime('%Y-%m-%d %H:%M') }}</span>
                </div>
                
                <div class="info-item">
                    <i class="fas fa-user me-2"></i>
                    <span class="info-label">归属用户:</span>
                    <span class="info-value">{{ script.user.username }}</span>
                </div>
            </div>
        </div>
        
        <div class="script-card-footer">
            <div class="script-actions">
                <a href="{{ url_for('edit_script', script_id=script.id) }}" 
                   class="btn btn-outline-primary btn-sm" title="编辑脚本">
                    <i class="fas fa-edit"></i>
                    <span>编辑</span>
                </a>
                
                <a href="{{ url_for('download_script', script_id=script.id) }}" 
                   class="btn btn-outline-success btn-sm" title="下载脚本">
                    <i class="fas fa-download"></i>
                    <span>下载</span>
                </a>
                
                <a href="{{ url_for('delete_script_page', script_id=script.id) }}" 
                   class="btn btn-outline-danger btn-sm" 
                   onclick="return confirm('确定要删除这个脚本吗？');" title="删除脚本">
                    <i class="fas fa-trash"></i>
                    <span>删除</span>
                </a>
            </div>
        </div>
    </div>
    {% endfor %}
</div>
{% else %}
<div class="empty-state">
    <div class="empty-icon">
        <i class="fas fa-code"></i>
    </div>
    <h4>暂无脚本</h4>
    <p>您还没有上传任何脚本，点击下方按钮开始上传</p>
    <a href="{{ url_for('upload_script') }}" class="btn btn-primary">
        <i class="fas fa-upload me-2"></i>
        上传第一个脚本
    </a>
</div>
{% endif %}

<style>
/* 液态玻璃效果基础样式 */
.page-header {
    background: rgba(255, 255, 255, 0.1) !important;
    backdrop-filter: blur(20px) !important;
    -webkit-backdrop-filter: blur(20px) !important;
    border: 1px solid rgba(255, 255, 255, 0.2) !important;
    border-radius: 15px;
    padding: 2rem;
    margin-bottom: 2rem;
    box-shadow: 
        0 8px 32px rgba(0, 0, 0, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.2) !important;
    position: relative;
    overflow: hidden;
}

.page-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, transparent 50%);
    pointer-events: none;
    opacity: 0.6;
}

/* 暗色模式页面头部 */
[data-theme="dark"] .page-header {
    background: rgba(0, 0, 0, 0.3) !important;
    border-color: rgba(255, 255, 255, 0.1) !important;
    box-shadow: 
        0 8px 32px rgba(0, 0, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.1) !important;
}

[data-theme="dark"] .page-header::before {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.05) 0%, transparent 50%);
}

.page-title {
    font-size: 2rem;
    font-weight: 700;
    color: #1C1C1E !important;
    margin-bottom: 0.5rem;
    position: relative;
    z-index: 2;
}

.page-subtitle {
    color: #6c757d !important;
    margin-bottom: 0;
    position: relative;
    z-index: 2;
}

/* 暗色模式标题和副标题 */
[data-theme="dark"] .page-title {
    color: #ffffff !important;
}

[data-theme="dark"] .page-subtitle {
    color: #bdc3c7 !important;
}

/* 上传脚本按钮液态玻璃效果 */
.btn-add {
    background: rgba(255, 255, 255, 0.1) !important;
    backdrop-filter: blur(15px) !important;
    -webkit-backdrop-filter: blur(15px) !important;
    border: 1px solid rgba(255, 255, 255, 0.2) !important;
    color: #1C1C1E !important;
    padding: 0.75rem 1.5rem;
    border-radius: 10px;
    font-weight: 600;
    box-shadow: 
        0 4px 12px rgba(0, 0, 0, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.1) !important;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    position: relative;
    overflow: hidden;
}

.btn-add::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, transparent 50%);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.btn-add:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 
        0 6px 20px rgba(0, 0, 0, 0.15),
        0 4px 12px rgba(0, 0, 0, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.2) !important;
    border-color: rgba(255, 255, 255, 0.3) !important;
    background: rgba(255, 255, 255, 0.15) !important;
    color: #1C1C1E !important;
}

.btn-add:hover::before {
    opacity: 1;
}

/* 暗色模式上传按钮 */
[data-theme="dark"] .btn-add {
    background: rgba(0, 0, 0, 0.3) !important;
    border-color: rgba(255, 255, 255, 0.2) !important;
    color: #ffffff !important;
    box-shadow: 
        0 4px 12px rgba(0, 0, 0, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.1) !important;
}

[data-theme="dark"] .btn-add::before {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.08) 0%, transparent 50%);
}

[data-theme="dark"] .btn-add:hover {
    background: rgba(0, 0, 0, 0.4) !important;
    border-color: rgba(255, 255, 255, 0.3) !important;
    color: #ffffff !important;
    box-shadow: 
        0 6px 20px rgba(0, 0, 0, 0.3),
        0 4px 12px rgba(0, 0, 0, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.15) !important;
}

.scripts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

/* 脚本卡片液态玻璃效果 */
.script-card {
    background: rgba(255, 255, 255, 0.1) !important;
    backdrop-filter: blur(20px) !important;
    -webkit-backdrop-filter: blur(20px) !important;
    border: 1px solid rgba(255, 255, 255, 0.2) !important;
    border-radius: 15px;
    box-shadow: 
        0 8px 32px rgba(0, 0, 0, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.2) !important;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    position: relative;
}

.script-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, transparent 50%);
    pointer-events: none;
    opacity: 0.6;
    z-index: 0;
}

.script-card > * {
    position: relative;
    z-index: 1;
}

/* 暗色模式脚本卡片 */
[data-theme="dark"] .script-card {
    background: rgba(0, 0, 0, 0.3) !important;
    border-color: rgba(255, 255, 255, 0.1) !important;
    box-shadow: 
        0 8px 32px rgba(0, 0, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.1) !important;
}

[data-theme="dark"] .script-card::before {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.05) 0%, transparent 50%);
}

.script-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.15);
}

/* 暗黑模式下的脚本卡片悬停效果 */
[data-theme="dark"] .script-card:hover {
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.5);
}

/* 脚本卡片头部液态玻璃效果 */
.script-card-header {
    background: rgba(255, 255, 255, 0.15) !important;
    backdrop-filter: blur(15px) !important;
    -webkit-backdrop-filter: blur(15px) !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2) !important;
    color: #1C1C1E !important;
    padding: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    overflow: hidden;
}

.script-card-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.2) 0%, transparent 50%);
    pointer-events: none;
    opacity: 0.8;
}

.script-card-header > * {
    position: relative;
    z-index: 1;
}

/* 暗色模式脚本卡片头部 */
[data-theme="dark"] .script-card-header {
    background: rgba(0, 0, 0, 0.4) !important;
    border-bottom-color: rgba(255, 255, 255, 0.1) !important;
    color: #ffffff !important;
}

[data-theme="dark"] .script-card-header::before {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, transparent 50%);
}

.script-icon {
    font-size: 2rem;
    opacity: 0.9;
}

/* Python徽章液态玻璃效果 */
.script-type {
    display: flex;
    gap: 0.5rem;
}

.script-type .badge {
    background: rgba(255, 255, 255, 0.15) !important;
    backdrop-filter: blur(10px) !important;
    -webkit-backdrop-filter: blur(10px) !important;
    border: 1px solid rgba(255, 255, 255, 0.2) !important;
    color: #1C1C1E !important;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-weight: 600;
    font-size: 0.875rem;
    box-shadow: 
        0 2px 8px rgba(0, 0, 0, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.2) !important;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    position: relative;
    overflow: hidden;
}

.script-type .badge::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.2) 0%, transparent 50%);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    border-radius: 20px;
}

.script-type .badge:hover {
    transform: translateY(-1px) scale(1.02);
    box-shadow: 
        0 4px 12px rgba(0, 0, 0, 0.15),
        0 2px 8px rgba(0, 0, 0, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.3) !important;
    border-color: rgba(255, 255, 255, 0.3) !important;
    background: rgba(255, 255, 255, 0.2) !important;
    color: #1C1C1E !important;
}

.script-type .badge:hover::before {
    opacity: 1;
}

/* 暗色模式Python徽章 */
[data-theme="dark"] .script-type .badge {
    background: rgba(0, 0, 0, 0.3) !important;
    border-color: rgba(255, 255, 255, 0.2) !important;
    color: #ffffff !important;
    box-shadow: 
        0 2px 8px rgba(0, 0, 0, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.1) !important;
}

[data-theme="dark"] .script-type .badge::before {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, transparent 50%);
}

[data-theme="dark"] .script-type .badge:hover {
    background: rgba(0, 0, 0, 0.4) !important;
    border-color: rgba(255, 255, 255, 0.3) !important;
    color: #ffffff !important;
    box-shadow: 
        0 4px 12px rgba(0, 0, 0, 0.3),
        0 2px 8px rgba(0, 0, 0, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.15) !important;
}

/* 脚本卡片主体液态玻璃效果 */
.script-card-body {
    background: rgba(255, 255, 255, 0.05) !important;
    backdrop-filter: blur(10px) !important;
    -webkit-backdrop-filter: blur(10px) !important;
    padding: 1.5rem;
    position: relative;
    overflow: hidden;
}

.script-card-body::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.05) 0%, transparent 50%);
    pointer-events: none;
    opacity: 0.4;
}

.script-card-body > * {
    position: relative;
    z-index: 1;
}

/* 暗色模式脚本卡片主体 */
[data-theme="dark"] .script-card-body {
    background: rgba(0, 0, 0, 0.2) !important;
    color: #ffffff !important;
}

[data-theme="dark"] .script-card-body::before {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.03) 0%, transparent 50%);
}

/* 统一脚本卡片信息区颜色变量 */
.script-name {
    color: var(--text-primary);
}
[data-theme="dark"] .script-name {
    color: var(--text-primary);
}
.info-label {
    color: var(--text-secondary);
}
[data-theme="dark"] .info-label {
    color: var(--text-secondary);
}
.info-value {
    color: var(--text-primary);
}
[data-theme="dark"] .info-value {
    color: var(--text-primary);
}

/* 脚本卡片页脚液态玻璃效果 */
.script-card-footer {
    background: rgba(255, 255, 255, 0.1) !important;
    backdrop-filter: blur(15px) !important;
    -webkit-backdrop-filter: blur(15px) !important;
    border-top: 1px solid rgba(255, 255, 255, 0.2) !important;
    padding: 1rem 1.5rem;
    position: relative;
    overflow: hidden;
}

.script-card-footer::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, transparent 50%);
    pointer-events: none;
    opacity: 0.6;
}

.script-card-footer > * {
    position: relative;
    z-index: 1;
}

/* 暗色模式脚本卡片页脚 */
[data-theme="dark"] .script-card-footer {
    background: rgba(0, 0, 0, 0.3) !important;
    border-top-color: rgba(255, 255, 255, 0.1) !important;
}

[data-theme="dark"] .script-card-footer::before {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.05) 0%, transparent 50%);
}

.script-actions {
    display: flex;
    gap: 0.75rem;
}

/* 脚本操作按钮液态玻璃效果 */
.script-actions .btn {
    background: rgba(255, 255, 255, 0.1) !important;
    backdrop-filter: blur(15px) !important;
    -webkit-backdrop-filter: blur(15px) !important;
    border: 1px solid rgba(255, 255, 255, 0.2) !important;
    color: #1C1C1E !important;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-weight: 500;
    box-shadow: 
        0 2px 8px rgba(0, 0, 0, 0.05),
        inset 0 1px 0 rgba(255, 255, 255, 0.1) !important;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    position: relative;
    overflow: hidden;
}

.script-actions .btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, transparent 50%);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.script-actions .btn:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 
        0 6px 20px rgba(0, 0, 0, 0.1),
        0 2px 8px rgba(0, 0, 0, 0.05),
        inset 0 1px 0 rgba(255, 255, 255, 0.2) !important;
    border-color: rgba(255, 255, 255, 0.3) !important;
    background: rgba(255, 255, 255, 0.15) !important;
    color: #1C1C1E !important;
}

.script-actions .btn:hover::before {
    opacity: 1;
}

/* 暗色模式操作按钮 */
[data-theme="dark"] .script-actions .btn {
    background: rgba(0, 0, 0, 0.3) !important;
    border-color: rgba(255, 255, 255, 0.2) !important;
    color: #ffffff !important;
    box-shadow: 
        0 2px 8px rgba(0, 0, 0, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.1) !important;
}

[data-theme="dark"] .script-actions .btn::before {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.08) 0%, transparent 50%);
}

[data-theme="dark"] .script-actions .btn:hover {
    background: rgba(0, 0, 0, 0.4) !important;
    border-color: rgba(255, 255, 255, 0.3) !important;
    color: #ffffff !important;
    box-shadow: 
        0 6px 20px rgba(0, 0, 0, 0.3),
        0 2px 8px rgba(0, 0, 0, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.15) !important;
}

/* 空状态区域液态玻璃效果 */
.empty-state {
    background: rgba(255, 255, 255, 0.1) !important;
    backdrop-filter: blur(20px) !important;
    -webkit-backdrop-filter: blur(20px) !important;
    border: 1px solid rgba(255, 255, 255, 0.2) !important;
    text-align: center;
    padding: 4rem 2rem;
    border-radius: 15px;
    box-shadow: 
        0 8px 32px rgba(0, 0, 0, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.2) !important;
    position: relative;
    overflow: hidden;
}

.empty-state::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, transparent 50%);
    pointer-events: none;
    opacity: 0.6;
}

.empty-state > * {
    position: relative;
    z-index: 1;
}

/* 暗色模式空状态区域 */
[data-theme="dark"] .empty-state {
    background: rgba(0, 0, 0, 0.3) !important;
    border-color: rgba(255, 255, 255, 0.1) !important;
    box-shadow: 
        0 8px 32px rgba(0, 0, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.1) !important;
}

[data-theme="dark"] .empty-state::before {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.05) 0%, transparent 50%);
}

.empty-icon {
    font-size: 4rem;
    color: var(--secondary-color);
    margin-bottom: 1.5rem;
    opacity: 0.5;
}

.empty-state h4 {
    color: var(--dark-color);
    margin-bottom: 1rem;
    font-weight: 600;
}

.empty-state p {
    color: var(--secondary-color);
    margin-bottom: 2rem;
    font-size: 1.1rem;
}

@media (max-width: 768px) {
    .page-header {
        padding: 1.5rem;
    }
    
    .page-title {
        font-size: 1.5rem;
    }
    
    .scripts-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .script-card-header {
        padding: 1rem;
    }
    
    .script-card-body {
        padding: 1rem;
    }
    
    .script-card-footer {
        padding: 1rem;
    }
    
    .script-actions {
        flex-direction: column;
    }
}
</style>
{% endblock %}